package wetalk.software.bupt.com.wetalk.BroadcastReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import com.google.gson.Gson;

import wetalk.software.bupt.com.wetalk.DB.WeTalkDB;
import wetalk.software.bupt.com.wetalk.model.po.User;
import wetalk.software.bupt.com.wetalk.view.dialog.CustomDialog;

public class AcceptAddReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        SharedPreferences.Editor editor= context.getSharedPreferences("data",Context.MODE_PRIVATE).edit();
        String content=intent.getStringExtra("content");
        User user=new Gson().fromJson(content,User.class);
        if(user.getUserName()!=null){
            User u= WeTalkDB.create(context).queryFri(user.getUserID());
            if(u==null){
                WeTalkDB.create(context).addFri(user);
            }
            editor.putString("isAdd","yes");
            editor.apply();
        }
        abortBroadcast();
    }
}
